package com.base.study.presenter;

import android.app.Activity;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.study.bean.OnlineStudyListBean;
import com.base.study.bean.ScopeBean;
import com.base.study.view.MyStudyListView;
import com.base.study.view.OnlineStudyListView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2020/2/21.
 */

public class MyStudyListPresenter extends BasePresenter<MyStudyListView> {
    public MyStudyListPresenter(MyStudyListView view, Activity activity) {
        super(view, activity);
    }

    /*
    public void getList(final Integer page, Integer limit){
        Map<String, Integer> map = new HashMap<>();
        map.put("page",page);
        map.put("limit", limit);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-train/course/query").content(map)
                .build().enqueue(OnlineStudyListBean.class, new CallBackImpl<OnlineStudyListBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnError();
                    }

                    @Override
                    public void onNext(OnlineStudyListBean list) {
                        if (page==1){
                            //刷新
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnList(list);
                                //mView.returnNoData();
                            }else {
                                mView.returnNoData();
                            }
                        }else {
                            //更多
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnMoreList(list);
                            }else {
                                mView.returnNoMoreData();
                            }
                        }
                    }
                });

        mCompositeDisposable.add(enqueue);
    }
    */

    public void getMyStudyList(final Integer page, Integer limit){
        Map<String, Integer> map = new HashMap<>();
        map.put("page",page);
        map.put("limit", limit);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-train/app/myLearnList").content(map)
                .build().enqueueForArray(OnlineStudyListBean.class, new CallBackImpl<List<OnlineStudyListBean>>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnError();
                    }

                    @Override
                    public void onNext(List<OnlineStudyListBean> list) {
                        if (page==1){
                            //刷新
                            if (list!=null &&list != null&&list.size()>0){
                                mView.returnList(list);
                                //mView.returnNoData();
                            }else {
                                mView.returnNoData();
                            }
                        }else {
                            //更多
                            if (list!=null &&list != null&&list.size()>0){
                                mView.returnMoreList(list);
                            }else {
                                mView.returnNoMoreData();
                            }
                        }
                    }
                });

        mCompositeDisposable.add(enqueue);
    }


    /**
     * 获取积分
     */
    public void getScope(String str){
        mView.showPb();
        Map<String, String> map = new HashMap<>();
        map.put("funcMainId",str);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-function/integral/getInfo").content(map)
                .build().enqueue(ScopeBean.class, new CallBackImpl<ScopeBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb();
                        mView.showError();
                        mView.returnError();
                    }

                    @Override
                    public void onNext(ScopeBean sc) {
                        mView.hidePb();
                        mView.returnScope(sc);
                    }
                });

        mCompositeDisposable.add(enqueue);
    }
}
